﻿//----------------------------------------------------------------
// Copyright (c) 2011-2013 
// All rights reserved.
// Author: Ben DaoWei 
// Contact: bendaowei@gmail.com
// Web Link: http://xnaeditor.codeplex.com
// ----------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MdxLib.Model;
using MdxLib.Animator;

namespace UnityEngine.Graphics
{
    public class GeosetAnimationRenderer
    {
        public CGeosetAnimation GeosetAnimation { get; set; }

        public GeosetRenderer GeosetRenderer { get; set; }

        public GeosetAnimationRenderer(CGeosetAnimation geosetAnimation, List<GeosetRenderer> renderers)
        {
            this.GeosetAnimation = geosetAnimation;

            if (geosetAnimation.Geoset.ObjectId >= 0)
                this.GeosetRenderer = renderers[geosetAnimation.Geoset.ObjectId];
            else
                this.GeosetRenderer = null;
        }

        public void Update(int CurrentTick)
        {
            if (this.GeosetRenderer != null)
                GeosetRenderer.Alpha = GetCurrentAlpha(CurrentTick);
            else
                GeosetRenderer.Alpha = 1.0f;
        }


        private float GetCurrentAlpha(int tick)
        {
            float ret = 1.0f;

            CAnimator<float> animator = this.GeosetAnimation.Alpha;

            ret = animator.GetValue(new CTime(tick));

            return ret;
        }
    }
}
